/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ge.info.pages;

import ge.info.logging.Session;
import ge.info.sip.SessionMap;
import javax.servlet.http.HttpServletRequest;
import org.apache.tapestry.BaseComponent;
import org.apache.tapestry.annotations.InjectObject;
import org.apache.tapestry.event.PageBeginRenderListener;
import org.apache.tapestry.event.PageEvent;




/**
 *-
 * @author koka
 */
public abstract class Phones extends BaseComponent implements PageBeginRenderListener
        
  

{

    
    @InjectObject("service:tapestry.globals.HttpServletRequest")
    public abstract HttpServletRequest getRequest();

    @InjectObject("spring:CurrentSessions")
    public abstract SessionMap getCurrentSessions();

    @InjectObject("spring:PreviousSessions")
    public abstract SessionMap getPreviousSessions();

    public abstract String getCurrentPhone();

    public abstract void setCurrentPhone(String phone);

    public abstract String getPreviousPhone();

    public abstract void setPreviousPhone(String phone);

    public abstract String getCurrentName();

    public abstract void setCurrentName(String name);

    public abstract String getPreviousName();

    public abstract void setPreviousName(String name);
    
    public abstract void setCurrentDebt(String s);
    public abstract String getCurrentDebt();

    public abstract void setPreviousDebt(String s);
    public abstract String getPreviousDebt();

    public abstract int getCurrentSex();
    public abstract void setCurrentSex(int sex);

     public abstract int getCurrentCbd();
    public abstract void setCurrentCbd(int cbd);

    public abstract int getPreviousSex();
    public abstract void setPreviousSex(int cbd);

 
    

        public Session getSession()
    {
        return getCurrentSessions().get(getRequest().getRemoteAddr());
    }

    public void pageBeginRender(PageEvent event)
    {


        if (!event.getRequestCycle().isRewinding())
        {
            SessionMap sm = getCurrentSessions();

            String ip = getRequest().getRemoteAddr();
            Session ev = getCurrentSessions().get(ip);
            if (ev != null)
            {


                setCurrentPhone(ev.getPhone());                
                setCurrentName(ev.getDisplayName());
                setCurrentDebt(ev.getDebts());
                setCurrentSex(ev.getSex());
                setCurrentCbd(ev.getCbd());

            }
            ev = getPreviousSessions().get(ip);
            if (ev != null)
            {
                setPreviousPhone(ev.getPhone());
                setPreviousName(ev.getDisplayName());
                setPreviousDebt(ev.getDebts());
                setPreviousSex(ev.getSex());
            }
            
        }
    }
    
}
